package com.yy.yyui.button
{
	
	import com.maqie.GlobalConfig;
	import com.yy.yyui.IClick;
	import com.yy.yyui.IDataContainer;
	import com.util.tools.ArrayTools;
	import com.util.tools.GT;
	
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;

	public class ImageButton extends SimpleButton implements IClick,IDataContainer
	{
		
		private var _actions:Object;
		private var _data:Object;
		private var oldFilters:Array;
		private var disableFilters:Array;
		public function ImageButton(button:SimpleButton,upState:DisplayObject=null, overState:DisplayObject=null, downState:DisplayObject=null, hitTestState:DisplayObject=null,rotation:Boolean = true,offsetX:Number=0,offsetY:Number=0){
			super(button.upState==null?upState:button.upState, 
				button.overState==null?overState:button.overState,
				button.downState==null?downState:button.downState,
				button.hitTestState==null?hitTestState:button.hitTestState);
			//GT.enableMouseDownAlphaEffect(this);
			if(rotation)
			{
				GT.enableButtonClickDownEffect(button,offsetX,offsetY);	
			}
			this.addEventListener(MouseEvent.CLICK,clickHandler);
			this._actions = {};
			this.cacheAsBitmap = true;
			
		}
		public function set onClick(value:Function):void{
			this.actions.onClick = value;
		}
		
		public function get onClick():Function{
			return this.actions.onClick;
		}
		
		private function clickHandler(e:MouseEvent):void{
			this.actions.onClick(e);
		}
		
		public function get actions():Object{
			return this._actions;
		}
		
		override public function set enabled(value:Boolean):void{
			var oldValue:Boolean = this.enabled;
			super.enabled =  value;
			this.mouseEnabled = value; 
			
			if(value!=oldValue){
				if(oldValue){
					this.oldFilters = ArrayTools.add(this.filters,new Array());
					this.filters = ArrayTools.add(this.filters,GlobalConfig.BUTTON_DISABLE_FILTER);
				}else{
					this.filters = ArrayTools.add(this.oldFilters,new Array());
				}
			}
			
//			
//			if(value){
//				this.filters = null;
//				//this.filters = oldFilters;
//			}else{
//				if(this.oldFilters==null){
//					this.oldFilters = new Array();
//					if(this.filters!=null){
//						this.oldFilters = ArrayTools.add(this.filters,this.oldFilters);					
//					}
//				}
//				this.filters = ArrayTools.add(this.filters,Sys.BUTTON_DISABLE_FILTER);
//			}
		}
		public function get data():Object{return _data;}
		public function set data(value:Object):void{this._data = value;}

	}
}